package dtos

import (
	"fmt"

	"cashew.com/cashew_common/configs"
	"github.com/pkg/errors"
)

type Response struct {
	Result int         `json:"result"`
	Msg    string      `json:"msg"`
	Data   interface{} `json:"data"`
}

func HttpBuildResponse(resultCode int, data interface{}) (*Response, error) {
	msg, ok := configs.HttpResponseMap[resultCode]
	if !ok {
		return nil, errors.New("HttpBuildResponse::result code error")
	}
	return &Response{Result: resultCode, Msg: fmt.Sprintf("%v", msg), Data: data}, nil
}
